﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using Lenovo.CFI.BLL;
using Lenovo.CFI.Common.Dic;
using Lenovo.CFI.WebControls;
using Lenovo.CFI.Web.Helper;
using Lenovo.CFI.Common;
using Lenovo.CFI.BLL.Sys;
using Lenovo.CFI.BLL.DicMgr;

namespace Lenovo.CFI.Web.VP
{
    public partial class TopicDetail : System.Web.UI.UserControl
    {
        TopicBl topicBl = new TopicBl();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int? id = UrlHelper.GetQueryStringID();
                Topic topic = null;
                if (id.HasValue)
                {
                    topic = topicBl.GetTopicByID(id.Value);
                }
                if (topic == null) ErrorHelper.RaiseNoValueError();

                ViewState["id"] = topic.ID;


                this.TxtTitle.Text = topic.Title;
                this.TxtNo.Text = topic.No;
                this.TxtType.Text = TopicTypeDicMgr.GetByCode(topic.Type).Title;
                this.TxtTdc.Text = topic.Tdc;
                if (topic.PptFileID.HasValue)
                    this.TxtFile.Text = String.Format(@"<a href=""{0}"" target=""_blank"">{1}</a>", 
                        AttachmentUrl.GetFileUrl(topic.PptFileID.Value, false), new AttachmentBl().GetAttachmentByID(topic.PptFileID.Value).Title);
                this.TxtStart.Text = topic.StartTime.HasValue ? topic.StartTime.Value.ToString("yyyy-MM-dd") : "";
                this.TxtDeadline.Text = topic.DeadlineTime.HasValue ? topic.DeadlineTime.Value.ToString("yyyy-MM-dd") : "";
                this.TxtReview.Text = topic.ReviewTime.HasValue ? topic.ReviewTime.Value.ToString("yyyy-MM-dd") : "";
            }
        }


        protected void RepDcAndIp_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                IdeaType ideaType = (IdeaType)e.Item.DataItem;
                ((Label)e.Item.FindControl("LblDcOwner")).Text = ideaType.Title;
                ((Label)e.Item.FindControl("TxtDcOwner")).Text = ideaType.DC;
            }
        }
    }
}